home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 January / PCWorld_2007-01_cd.bin / v cisle / hotkey / AutoHotkey104504_Install.exe / AutoHotkey.chm / docs / scripts / joysticktest.ahk < prev    next >
Text File  |  2006-11-15  |  3KB  |  89 lines

  1. ; Joystick Test Script
  2. ; http://www.autohotkey.com
  3. ; This script helps determine the button numbers and other attributes
  4. ; of your joystick. It might also reveal if your joystick is in need
  5. ; of calibration; that is, whether the range of motion of each of its
  6. ; axes is from 0 to 100 percent as it should be. If calibration is
  7. ; needed, use the operating system's control panel or the software
  8. ; that came with your joystick.
  9.  
  10. ; July 6, 2005: Added auto-detection of joystick number.
  11. ; May 8, 2005 : Fixed: JoyAxes is no longer queried as a means of
  12. ; detecting whether the joystick is connected.  Some joysticks are
  13. ; gamepads and don't have even a single axis.
  14.  
  15. ; If you want to unconditionally use a specific joystick number, change
  16. ; the following value from 0 to the number of the joystick (1-32).
  17. ; A value of 0 causes the joystick number to be auto-detected:
  18. JoystickNumber = 0
  19.  
  20. ; END OF CONFIG SECTION. Do not make changes below this point unless
  21. ; you wish to alter the basic functionality of the script.
  22.  
  23. ; Auto-detect the joystick number if called for:
  24. if JoystickNumber <= 0
  25. {
  26.     Loop 32  ; Query each joystick number to find out which ones exist.
  27.     {
  28.         GetKeyState, JoyName, %A_Index%JoyName
  29.         if JoyName <>
  30.         {
  31.             JoystickNumber = %A_Index%
  32.             break
  33.         }
  34.     }
  35.     if JoystickNumber <= 0
  36.     {
  37.         MsgBox The system does not appear to have any joysticks.
  38.         ExitApp
  39.     }
  40. }
  41.  
  42. #SingleInstance
  43. SetFormat, float, 03  ; Omit decimal point from axis position percentages.
  44. GetKeyState, joy_buttons, %JoystickNumber%JoyButtons
  45. GetKeyState, joy_name, %JoystickNumber%JoyName
  46. GetKeyState, joy_info, %JoystickNumber%JoyInfo
  47. Loop
  48. {
  49.     buttons_down =
  50.     Loop, %joy_buttons%
  51.     {
  52.         GetKeyState, joy%a_index%, %JoystickNumber%joy%a_index%
  53.         if joy%a_index% = D
  54.             buttons_down = %buttons_down%%a_space%%a_index%
  55.     }
  56.     GetKeyState, joyx, %JoystickNumber%JoyX
  57.     axis_info = X%joyx%
  58.     GetKeyState, joyy, %JoystickNumber%JoyY
  59.     axis_info = %axis_info%%a_space%%a_space%Y%joyy%
  60.     IfInString, joy_info, Z
  61.     {
  62.         GetKeyState, joyz, %JoystickNumber%JoyZ
  63.         axis_info = %axis_info%%a_space%%a_space%Z%joyz%
  64.     }
  65.     IfInString, joy_info, R
  66.     {
  67.         GetKeyState, joyr, %JoystickNumber%JoyR
  68.         axis_info = %axis_info%%a_space%%a_space%R%joyr%
  69.     }
  70.     IfInString, joy_info, U
  71.     {
  72.         GetKeyState, joyu, %JoystickNumber%JoyU
  73.         axis_info = %axis_info%%a_space%%a_space%U%joyu%
  74.     }
  75.     IfInString, joy_info, V
  76.     {
  77.         GetKeyState, joyv, %JoystickNumber%JoyV
  78.         axis_info = %axis_info%%a_space%%a_space%V%joyv%
  79.     }
  80.     IfInString, joy_info, P
  81.     {
  82.         GetKeyState, joyp, %JoystickNumber%JoyPOV
  83.         axis_info = %axis_info%%a_space%%a_space%POV%joyp%
  84.     }
  85.     ToolTip, %joy_name% (#%JoystickNumber%):`n%axis_info%`nButtons Down: %buttons_down%`n`n(right-click the tray icon to exit)
  86.     Sleep, 100
  87. }
  88. return
  89.